<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
 <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@taglib uri="/struts-tags" prefix="s"%>
<%@page isELIgnored="false"%>

<html>
  <head>
   <script type="text/javascript" src="<%=request.getContextPath()%>/js/jquery.min.js"></script>
  </head>
  
  <body>
  <script type="text/javascript">
  		function gotoAdd(){
  			var name = $("#td1").children().eq(0).val();
  			var leixing = $("#td2").children().eq(0).val();
  			location.href="<%=request.getContextPath()%>/new/addTodo?name="+name+"&leixing="+leixing;
  		}
  		
  		function panduan(){
  			var name = $("#td1").children().eq(0).val();
  			
  			
  			
  			var xhr = new XMLHttpRequest();
  			xhr.onreadystatechange=function(){
  				if(xhr.readyState==4){
  					//	alert(xhr.responseText);
  						var hr=xhr.responseText;
  						//var ad=$("#pb").children().html("name已存在");
  					if(name==""){
  				       var ad=$("#pb").children().html("name不能为空");
  			        }else{
  					if((hr==1)==false){
  						var ad=$("#pb").children().html("name可以使用");
  					}else{
  						var ad=$("#pb").children().html("name已存在");
  					}
  				}
  			}
  			}
  			xhr.open("get","/todo/new/selectTodoByName?name="+name,false);
  			xhr.send();
  			
  		}
  		
  </script>
	  <form action="" method="get">
	   	<table border="0" align="center">
	   		<tr>
	   			<td>name:</td>
	   			<td id="td1"><input onblur="panduan(this)" type="text" value=""/></td>
	   			<td></td>
	   		</tr>
	   		<tr>
	   			<td>leixing:</td>
	   			<td id="td2"><input type="text"  value=""/></td>
	   		</tr>
			<tr>
				<td id="pb">
					<font color="red">${requestScope.error}</font>
				</td>
			</tr>
	   		<tr>
	   			<td>
	   				<input onclick="gotoAdd()" type="button" value="提交"/>
	   			</td>
	   		</tr>
	   	</table>
   	</from>
   	<s:debug></s:debug>
  </body>
</html>
